import {defineConfig} from 'vite'
import {resolve} from 'path'
import Components from 'unplugin-vue-components/vite'
import vue from '@vitejs/plugin-vue'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
// import postCssPxToRem from 'postcss-pxtorem'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
    extensions: ['.vue', '.js', '.jsx', '.ts', '.tsx', '.json'],
  },
  base: "/",

  server: {
    // http://localhost:5173/api/login -> http://www.test.com/login
    proxy: {
      //api是自行设置的请求前缀，任何请求路径以/api开头的请求将被代理到对应的target目标
      '/api': {
        target: 'http://175.24.229.44:8083', //目标域名
        changeOrigin: true, //需要代理跨域
        rewrite: (path) => path.replace(/^\/api/, ''), //路径重写，把'/api'替换为''
      }
    }
  },
  // css:{
  //   postcss:{
  //     plugins:[
  //       postCssPxToRem({
  //         rootValue:37.5,
  //         propList:['*'],
  //       })
  //     ]
  //   }
  // },

})
